window.onload = function () {
    //获取cookie
    let cookieStr = document.cookie;
    let cookirArr = cookieStr.split(";");
    let bool = false;
    let username;;
    for (let i = 0; i < cookirArr.length; i++) {
        //去除空格
        let str = cookirArr[i].trim();

        let key = "username=";
        if (str.startsWith(key)) {
            bool = true;
            username = str.substring(key.length, str.length);
            break;
        }
    }

    //判断bool标记值
    if (bool) {
    } else {
        location.href = "./register.html"
    }

    $.ajax({
        type: "post",
        url: "/js/index",
        data: null,
        dataType: "json",
        success: function (data) {
            //获取所有货物图片标签
            let imgList = document.getElementsByClassName("teagoodimg");
            //获取所有的名字标签
            let aList = document.getElementsByClassName("text-name");
            //获取所有的价格
            let spanList = document.getElementsByClassName("text-price");
            for (let index = 0; index < imgList.length; index++) {
                imgList[index].src = `../img/${data[index].teaImg}`;
                aList[index].innerHTML = data[index].teaName;
                spanList[index].innerHTML = `￥${data[index].teaPrice}`;
            }
        }
    })
    
    window.addEventListener("scroll", function () {
        
        let top = parseInt(document.documentElement.scrollTop);
        let bigbox = document.getElementById("bigbox");
      
        console.log(top);
        if (top >= 400) {
            debugger
            bigbox.style.animationName="donghua";
            bigbox.style.animationDuration="2s";
            bigbox.style.animationFillMode="forwards";



        }
    })
}
